﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Npgsql;

namespace frmPrincipal
{
    public partial class frmConEspecial : Form
    {
        StandardDBConnection standardDBConnection = new StandardDBConnection();
        string sqlCommandText;

        //Contrutor
        public frmConEspecial(string title, string sqlCommandText, int grdX, int grdY)
        {
            Size frmSize = new Size(grdX, grdY);
            Size grdSize = new Size(grdX - 36, grdY - 60);
            
            InitializeComponent();

            this.sqlCommandText = sqlCommandText;
            this.Text = title;
            this.Size = frmSize;
            grdConsulta.Size = grdSize;
        }

        //Funções Auxiliares
        private void reSize()
        {
            grdConsulta.Size = new Size(this.Size.Width - 36, this.Size.Height - 60);
        }

        //Funções Relacionadas ao Form
        private void frmConEspecial_Load(object sender, EventArgs e)
        {
            DataSet ds = new DataSet();
            DataTable dt = new DataTable();
            NpgsqlDataAdapter da;

            da = new NpgsqlDataAdapter(sqlCommandText, standardDBConnection.cnn);

            ds.Reset();
            da.Fill(ds);
            dt = ds.Tables[0];
            grdConsulta.DataSource = dt;
            standardDBConnection.cnn.Close();
        }
        private void frmConEspecial_Resize(object sender, EventArgs e)
        {
            reSize();
        }
        private void frmConEspecial_FormClosed(object sender, FormClosedEventArgs e)
        {
            
        }
    }
}
